package sparkCore

import sparkCore.util.CommonTools


object Demo05_accumulator {

  def main(args: Array[String]): Unit = {

    val sc = CommonTools.getSparkContext("accu")
    val list = List(1,2,3,4,5,6,7,8,9,10)

    val rdd = sc.parallelize(list,3)

    val sumAccu = sc.longAccumulator("sum")

    rdd.map(num=>{
      sumAccu.add(num)
      println(sumAccu.value+"======================")
      num+"^_^"
    }).foreach(println)

    println(sumAccu.value)

//    Thread.sleep(1000000000)
    sc.stop()
  }

}
